//
//  MyPerson.m
//  oclearn
//
//  Created by yons on 23.4.21.
//

#import "MyPerson.h"

#define MJTallMask (1<<0)
#define MJRichMask (1<<4)
#define MJHandsomeMask (1<<8)
#define MJThinMask (1<<12)


@interface MyPerson()
{
    union {
        int bits;
        struct {
            char tall : 4;
            char rich : 4;
            char handsome : 4;
            char thin : 4;
        };
    } _tallRichHandsome;
}
@end

@implementation MyPerson

/*
 
 与： 任何与0相与都是0，得到0
     任何与1相与都是本身，不变
 
 或： 任何与1相或都是1，得到1
     任何与0相或都是本身，不变
 
 */


- (void)setTall:(BOOL)tall
{
    /*
     if(yes){
        
        1.想控制的位得到1 --> 或上1
        2.其他位不变 --> 或上0
     
     }else{
        
        1.想控制的位得到0 --> 与上 0
        2.其他位不变 ---> 与上1
        
     }
     */
    
    
    if (tall) {
        _tallRichHandsome.bits |= MJTallMask;
    } else {
        _tallRichHandsome.bits &= ~MJTallMask;
    }
}

- (BOOL)isTall
{
    return !!(_tallRichHandsome.bits & MJTallMask);
}

- (void)setRich:(BOOL)rich
{
    if (rich) {
        _tallRichHandsome.bits |= MJRichMask;
    } else {
        _tallRichHandsome.bits &= ~MJRichMask;
    }
}

- (BOOL)isRich
{
    return !!(_tallRichHandsome.bits & MJRichMask);
}

- (void)setHandsome:(BOOL)handsome
{
    if (handsome) {
        _tallRichHandsome.bits |= MJHandsomeMask;
    } else {
        _tallRichHandsome.bits &= ~MJHandsomeMask;
    }
}

- (BOOL)isHandsome
{
    return !!(_tallRichHandsome.bits & MJHandsomeMask);
}



- (void)setThin:(BOOL)thin
{
    if (thin) {
        _tallRichHandsome.bits |= MJThinMask;
    } else {
        _tallRichHandsome.bits &= ~MJThinMask;
    }
}

- (BOOL)isThin
{
    return !!(_tallRichHandsome.bits & MJThinMask);
}




@end
